import java.util.LinkedHashMap;
import java.util.Map;

public class FunctionSymbol extends Symbol implements  Scope{
    Map<String, Symbol> arguments = new LinkedHashMap<String, Symbol>();
    Scope enclosingScope;
    FunctionSymbol(String name, Symbol.Type type, Scope enclosingScope) {
        super(name, type);
        this.enclosingScope = enclosingScope;
    }

    @Override
    public String getScopeName() {
        return name;
    }

    @Override
    public Scope getEnclosingScope() {
        return this.enclosingScope;
    }

    @Override
    public void define(Symbol symbol) {
        arguments.put(symbol.name, symbol);
        symbol.scope = this;
    }
    @Override
    public Symbol resolve(String name) {
        Symbol symbol = arguments.get(name);
        if (symbol != null) {
            return symbol;
        }
        if (getEnclosingScope() != null) {
            return getEnclosingScope().resolve(name);
        }
        return null;
    }
    @Override
    public String toString() {
        return "function" + super.toString() + ":" + arguments.values();
    }
}
